<?php
/**
 * Created by PhpStorm.
 * User: N
 * Date: 2017/12/13
 * Time: 15:17
 */
namespace common\models;

use Yii;
use yii\base\Model;
use common\models\Models;
use backend\modules\content\models\Sitemodel;
use backend\modules\content\models\Modelfield;
use yii\db\ActiveRecord;
use yii\data\ActiveDataProvider;
use yii\data\Pagination;


/**
 * This is the model class for table "Ntype".
 *
 * @property string $catid
 * @property string $siteid
 **/
class Ntype extends ActiveRecord
{
     /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%ntype}}';
    }


    public function getifshow($ifshow)
    {
        switch($ifshow){
            case 1:
                echo '是';
                break;
            case 0:
                echo  '否';
                break;
            default:
                echo '未知';
        }
    }

    /**
    * 验证规则
    */
    public function rules()
    {
        return [
            [['type_name'],'required','message'=>'不能为空'],
            [['type_name'],'string','message'=>'格式不正确'],
            [['type_id','parent_id','sort_order','if_show'],'number','message'=>'格式不正确'],
        ];
    }

    public function beforeSave($insert){
        if($insert){
            //$this->if_show=1;
            //插入时补充操作
            //$this->inputtime = time();
        }else{
            //修改时补充操作

        }
      
        return true;

    }



        /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'type_name' => '分类名称',
            'parent_id' => '上级分类id',
            'sort_order' => '排序',
            'if_show' => '是否显示'
        ];
    }

    


}